#include<bits/stdc++.h>
using namespace std;

struct Node{
	int state;
	string step;
	Node(){}
	Node(int state){
		this->state=state;
	}
};
unordered_map<int,bool> ump;

string moves[]={
	"","abde","abc","bcef",
	"adg","bdefh","cfi",
	"degh","ghi","efhi" 
};

int main(){
	int s0=0;
	for(int i=0;i<9;i++){
		s0*=4;
		int u;
		scanf("%d",&u);
		u=u/3%4;
		s0+=u;
	}
	if(s0==0){
		return 0;
	}
	Node node0;
	node0.state=s0;
	queue<Node> que;
    ump[s0]=true;
	que.push(node0);
	while(!que.empty())
	{
		int size=que.size();
		for(int i=0;i<size;i++)
		{
			Node node=que.front();
			que.pop();
			int state0=node.state;
			const string step0=node.step;
			int s[9];
			for(int k=8;k>=0;k--){
				s[k]=state0%4;
				state0/=4;
			}
			for(int j=1;j<=9;j++){
				int sj[9];
				for(int u=0;u<9;u++){
					sj[u]=s[u];
				}
				for(auto c:moves[j]){
					sj[c-'a']=(sj[c-'a']+1)%4;
				}
				int staten=0;
				for(int u=0;u<9;u++){
					staten*=4;
					staten+=sj[u];
				}
				Node noden;
				string stepn;
				stepn=step0+(char)(j+'0');
				noden.step=stepn;
				noden.state=staten;
                if(staten==0){
                    for(auto c:stepn){
						cout<<c<<' ';
					}
                    return 0;
                }
				if(!ump.count(staten)){
                    que.push(noden);
				}
				ump[staten]=true;
			}
		}
	}
	return 0;
}
